<template>
  <div>
    <header>
      <div class="l-content">
        <el-button
          plain
          icon="el-icon-menu"
          size="mini"
          @click="collpaseMenu"
        ></el-button>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item :to="current.path" v-if="current">{{
            current.label
          }}</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div class="r-content">
        <el-dropdown trigger="click" szie="mini">
          <span class="el-dropdown-link">
            <img :src="userImg" class="user" />
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click.native="logOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </header>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  computed: {
    ...mapState({
      current: (state) => state.tab.currentMenu,
    }),
  },
  data() {
    return {
      userImg: require('../assets/images/user.png'),
    }
  },
  methods: {
    collpaseMenu() {
      this.$store.commit('collapseMenu')
    },
    logOut() {
      this.$store.commit('clearToken')
      this.$store.commit('clearMenu')
      location.reload()
    },
  },
}
</script>

<style lang="scss" scoped>
header {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: space-between;
}

.l-content {
  display: flex;
  align-items: center;
  .el-button {
    margin-right: 20px;
  }
}

.r-content {
  .user {
    height: 40px;
    width: 40px;
    border-radius: 50%;
  }
}
</style>

<style type="scss">
/* 嵌套组件中的样式，不要用scope */
/* .el-breadcrumb__inner a,
.el-breadcrumb__inner.is-link {
  color: white;
} */

/* .el-breadcrumb__item:last-child .el-breadcrumb__inner {
  color: white;
} */

.el-breadcrumb__inner .el-breadcrumb__inner {
  color: #666;
  font-weight: normal;
}

.el-breadcrumb__item:last-child .el-breadcrumb__inner {
  color: #fff;
}
</style>
